/**
 * 项目名：phms3
 * 日期：    2019-12-08 11:33:38
 * Copyright (c) 2015- HTSC-版权所有
 */

package com.joysuch.wwyt.core.repository;

import com.joysuch.wwyt.core.entity.BaseRole;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import java.util.List;

/**
 * BaseRoleDao
 *
 */
public interface BaseRoleDao extends JpaRepository<BaseRole, Long>, QuerydslPredicateExecutor<BaseRole> {

    Page<BaseRole> findAll(Specification<BaseRole> spec, Pageable pageable);

    BaseRole save(BaseRole bean);

    void delete(BaseRole bean);

    BaseRole findFirstByName(String roleName);

    int countByName(String name);

    @Query(value = " select " +
            " role.* " +
            " from " +
            " WWYT_BASE_ROLE role " +
            " inner join wwyt_base_role_user_login_role lrole " +
            " on role.ID = lrole.ROLE_ID " +
            " and lrole.USER_ID = ?1 " +
            " where DELETE_FLAG = '0' "  , nativeQuery = true)
    List<BaseRole> findByUserId(Long id);
    
}
